package com.screencapture.utilities;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

public class AppUtils {
        public static BufferedImage mergeImages(BufferedImage bg, BufferedImage fg) {

                BufferedImage finalImage = new BufferedImage(bg.getWidth(),
                                bg.getHeight(), BufferedImage.TYPE_INT_ARGB);
                Graphics2D g = finalImage.createGraphics();
                g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
                g.drawImage(bg, 0, 0, null);
                g.drawImage(fg, 0, 0, null);
                
                g.dispose();
                
                return finalImage;
        }

        public static Point diffPoint(Point point1,
                        Point point2) {
                return new Point(point1.x - point2.x, point1.y - point2.y);
        }

        public static void clearImage(BufferedImage img) {
                Graphics2D g = (Graphics2D) img.getGraphics();
                Color bg = g.getBackground();
                g.setBackground(new Color(255, 255, 255, 0));
                g.clearRect(0, 0, img.getWidth(), img.getHeight());
                g.setBackground(bg);
        }

        public static BufferedImage copyImage(BufferedImage image) {
                BufferedImage finalImage = new BufferedImage(image.getWidth(),
                                image.getHeight(), BufferedImage.TYPE_INT_ARGB);
                finalImage.createGraphics().drawImage(image, image.getWidth(), image.getHeight(), null);
                return finalImage;
        }
        
        public static BufferedImage getImagePatch(int width, int height, Color color, boolean fill){
        	BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
            Graphics g = img.createGraphics();
            g.setColor(color);
            g.fillRect(0, 0, img.getWidth(), img.getHeight());
            g.dispose();
			return img;
        }
        
}
